//
//  ViewController.m
//  DeviceFingerPrinting
//
//  Created by CityDo on 2019/1/9.
//  Copyright © 2019 CityDo. All rights reserved.
//

#import "ViewController.h"
#import "DeviceFingerPrintingVC.h"
#import "UIDevice+CityDOFCUUID.h"
#import "CitydoChecklocationGPS.h"
#import "CHGTimer.h"



@interface ViewController () {
    CitydoChecklocationGPS *loc;

}
- (IBAction)click:(id)sender;

@property (strong, nonatomic) DeviceFingerPrintingVC *deviceFingerPrintingVC;
@property (copy, nonatomic) NSString *userId;
@property (copy, nonatomic) NSString *task1;

@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    loc= [CitydoChecklocationGPS sharedlocationGPS];
    [loc getAuthorization];//授权
    
//    self.task1 = [CHGTimer execTask:self
//                           selector:@selector(callDeviceFingerPrinting)
//                              start:2.0 interval:60.0
//                            repeats:YES
//                              async:YES];


    // Do any additional setup after loading the view, typically from a nib.
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"applicationDidBecomeActive" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"applicationWillResignActive" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"didFinishLaunchingWithOptions" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)callDeviceFingerPrinting {

    NSString *udid  = [[UIDevice currentDevice] uuid];
   
    self.userId = udid;
    NSDictionary *dict =  @{@"userId":self.userId};
    self.deviceFingerPrintingVC = [DeviceFingerPrintingVC sharedInstance];
    self.deviceFingerPrintingVC.deviceFingerPrintingURL = @"http://47.96.120.226:8480/crashmgmt/api/breakinfo/insert";
    
    NSDictionary *dictt = [DeviceFingerPrintingVC dicGetAllDeviceInfo:dict];
    NSDictionary *dicttt = [[DeviceFingerPrintingVC sharedInstance]mutableDict];
//    [_deviceFingerPrintingVC postExceptionMessage];
    [_deviceFingerPrintingVC getAllDeviceInfo:dict];
    [_deviceFingerPrintingVC getAddressInfo:dict];
    
}

- (IBAction)click:(id)sender {

    [self callDeviceFingerPrinting];
//        [self performSelector:@selector(test:)];
//    //    //
//        [[NSMutableDictionary dictionaryWithCapacity:0] setValue:nil forKey:@"key"];

}

//- (DeviceFingerPrintingVC *) deviceFingerPrintingVC
//{
//    if (!_deviceFingerPrintingVC) {
//        _deviceFingerPrintingVC = [[DeviceFingerPrintingVC alloc] init];
//    }
//    return _deviceFingerPrintingVC;
//}

- (void)viewWillAppear:(BOOL)animated {
//    if (!_deviceFingerPrintingVC) {
//        _deviceFingerPrintingVC = [[DeviceFingerPrintingVC alloc] init];
//    }

    if (!self.userId) {
        self.userId = @"";
    }

    [self callDeviceFingerPrinting];

}

- (void)applicationDidBecomeActive:(NSNotification *)notification
{
    NSLog(@"开始执行========applicationDidBecomeActive");
    [self callDeviceFingerPrinting];
}

//实现2个NSNotificationCenter所触发的事件方法
- (void)applicationWillResignActive:(NSNotification *)notification

{
    NSLog(@"开始执行==========applicationWillResignActive");
    [self callDeviceFingerPrinting];

}

- (void)didFinishLaunchingWithOptions:(NSNotification *)notification {
    NSLog(@"开始执行========didFinishLaunchingWithOptions");
}


@end
